package com.wxx.验证回文串;

/**
 * @author: Jetwang
 * @date: 2022/3/19 20:08
 * @description: Solution
 * 给定一个字符串，验证它是否是回文串，只考虑字母和数字字符，可以忽略字母的大小写。
 * @version: 1.0
 */
public class Solution02 {
    public static boolean isPalindrome(String s) {
        s = s.toLowerCase();
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            if (Character.isLetterOrDigit(s.charAt(i))) {
                builder.append(s.charAt(i));
            }
        }
        return builder.toString().equals(builder.reverse().toString());
    }

    public static void main(String[] args) {
        System.out.println(isPalindrome("race a car"));
        System.out.println(isPalindrome("A man, a plan, a canal: Panama"));
        System.out.println(isPalindrome("0P"));
    }
}
